package com.tree.service.impl;

import com.tree.dao.GrassDao;
import com.tree.entity.Grass;
import com.tree.service.GrassService;
import com.tree.util.PageCal;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
public class GrassServiceImpl implements GrassService {

    @Autowired
    private GrassDao grassDao;

    @Override
    public List<Grass> queryAll(int pageIndex, int rowSize) {
        //将页数转换为行数
        int rowIndex = PageCal.calculateRowIndex(pageIndex,rowSize);
        List<Grass> list = new ArrayList<>();
        list = grassDao.queryAll(rowIndex,rowSize);
        return list;
    }

    @Override
    public Grass query(String grassTerm) {
        Grass grass;
        grass = grassDao.query(grassTerm);
        if (grass != null && grass.getGrassTerm() != null)
            return grass;
        return null;
    }
}
